home *** CD-ROM | disk | FTP | other *** search
- ;-------T-------T------------------------T----------------------------------;
- ;Sprite example
- ;--------------
- ;This example shows you how to set up a 16 colour OCS sprite with a doubled
- ;X axis (32 pixels width). Those with hardware experience will know that it
- ;takes 4 sprite banks to do this successfully in OCS, which leaves you with
- ;another 4 banks to do with what you will.
- ;
- ;Notice that the screen is only 1 bitplane large, even though the sprite is
- ;16 colours. This is because the sprite is independent of the screen
- ;bitmap. You can access colours not in the screen by setting up a large
- ;palette and specifying the amount of colours in GS_AmtColours (in this
- ;case, we set 32 colours to access the sprite colour bank).
- ;
- ;Try moving the sprite around a bit with the mouse. The LMB exits the demo.
-
- INCDIR "INCLUDES:"
- INCLUDE "games/games_lib.i"
- INCLUDE "games/games.i"
-
- CALL MACRO
- jsr _LVO\1(a6)
- ENDM
-
- SECTION "Sprites",CODE
-
- ;===========================================================================;
- ; INITIALISE DEMO
- ;===========================================================================;
-
- STARTGMS
-
- Start: MOVEM.L A0-A6/D1-D7,-(SP)
- move.l GMSBase(pc),a6
- lea ScreenTags(pc),a0
- CALL AddScreen
- tst.l d0
- beq.s .Error_Screen
-
- move.l Screen(pc),a0
- lea SparkieTags(pc),a1
- CALL InitSprite
- tst.l d0
- beq.s .Error_Sparkie
-
- CALL ShowScreen
-
- bsr.s Main
-
- CALL InitJoyPorts ;Initialise ports.
-
- .ReturnToDOS
- move.l GMSBase(pc),a6
- move.l Sparkie(pc),a1
- CALL FreeSprite
- .Error_Sparkie
- move.l Screen(pc),a0
- CALL DeleteScreen
- .Error_Screen
- MOVEM.L (SP)+,A0-A6/D1-D7
- moveq #ERR_OK,d0
- rts
-
- ;===========================================================================;
- ; MAIN LOOP
- ;===========================================================================;
-
- Main: move.l Sparkie(pc),a1
- .loop addq.w #1,d7 ;Animation/Frame delay, so that
- btst #0,d7 ; our anim does not run too fast!
- beq.s .Mouse
- cmp.w #5,SPR_Frame(a1) ;Do the animation for the sprite.
- beq.s .reset ;(simply by increasing the frame
- addq.w #1,SPR_Frame(a1) ; number).
- bra.s .Mouse
- .reset clr.w SPR_Frame(a1)
-
- .Mouse moveq #JPORT1,d0 ;Read from port 1
- CALL ReadMouse ;Go get mouse position.
- move.w d0,d1
- asr.w #8,d0
- add.w d0,SPR_XPos(a1)
- ext.w d1
- add.w d1,SPR_YPos(a1)
- CALL WaitVBL ;Wait for a VBL.
- CALL UpdateSprite ;Put Sparkie on the screen.
- btst #MB_LMB,d0
- beq.s .loop
- rts
-
- ;===========================================================================;
- ; DATA
- ;===========================================================================;
-
- SparkieTags
- dc.l TAGS_SPRITE
- Sparkie dc.l 0
- dc.l SPA_Data,Gfx_Sparkie
- dc.l SPA_XCoord,100
- dc.l SPA_YCoord,100
- dc.l SPA_Width,16
- dc.l SPA_Height,21
- dc.l SPA_AmtColours,16
- dc.l SPA_ColStart,16
- dc.l SPA_Planes,2
- dc.l SPA_Attrib,XLONG
- dc.l TAGEND
-
- ScreenTags:
- dc.l TAGS_GAMESCREEN
- Screen: dc.l 0
- dc.l GSA_Palette,.palette
- dc.l GSA_AmtColours,32
- dc.l GSA_Planes,1
- dc.l GSA_Attrib,SPRITES|NOSCRBDR
- dc.l TAGEND
- .palette
- dc.l $000000,$000000,$000000,$000000,$000000,$000000,$000000,$000000
- dc.l $000000,$608080,$406060,$304040,$C0C000,$908000,$807000,$605000
- dc.l $10C020,$005000,$B000B0,$600060,$F02000,$901000,$B0B0B0,$F0F0F0
- dc.l $00B0F0,$006080,$506080,$90B0F0,$F0F000,$E0E000,$B0A000,$504000
-
- ;===========================================================================;
- ; ALL CHIP RAM DATA HERE
- ;===========================================================================;
-
- SECTION "Graphics",DATA_C
-
- Gfx_Sparkie:
- INCBIN "GMS:demos/data/RAW.Sparkie"
-